<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>运动员管理</title>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>运动员管理</title>
            <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
            <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
            <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
            <script src="../../res/layui/layui.js"></script>
            <script src="../../res/js/Tools.js"></script>
            <link rel="stylesheet" type="text/css" href="../AtsEmpCSS/atsEmpCss.css"/>
        </head>
<body>
<div class="demoTable">
    <div class="layui-inline">
        <input class="layui-input" name="selectTitle" placeholder="请输入运动员名称" id="selectTitle" autocomplete="off">
    </div>
    <div class="layui-input-inline">
        <input type="text" class="layui-input" id="startTimes" name="startTime" placeholder="请输入开始日期" autocomplete="off">
    </div>
    <div class="layui-input-inline">
        <input type="text" class="layui-input" id="endTimes" name="endTime"  placeholder="请输入结束日期" autocomplete="off">
    </div>
    <input type="button" id="seachTable" class="layui-btn layui-btn-sm" value="搜索" />
</div>
<table id="demo" lay-filter="test" ></table>
<script>
    var tableTwo = null;
    var table = null;
    layui.use('table', function() {
        var table = layui.table

            tableTwo = table.render({
                elem: '#demo'
                , height: 500
                , toolbar: '#toolbarDemo'
                , url: '../../UserseControllerAthlete/selectAll' //数据接口
                , page: true //开启分页
                , cols: [[ //表头
                    {type: 'checkbox', fixed: 'left'}
                    , {field: 'athleteName', title: '运动员名称', align: 'center'}
                    , {field: 'athleteSex', title: '性别', align: 'center'}
                    , {field: 'phone', title: '联系方式', align: 'center'}
                    , {field: 'expertSpecia', title: '专业', align: 'center'}
                    , {field: 'coachName', title: '教练员', align: 'center'}
                    , {title: '操作', fixed: 'right', width: 200, align: 'center', toolbar: '#barDemo'}
                ]]
            });
            //templet: "<div>{{layui.util.toDateString(d.roleTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"

            $(function () {
                $("#seachTable").on("click", function () {
                    //var name = document.getElementById("selectTitle").value;
                    //alert(name);
                    //执行重载
                    //带条件查询
                    tableTwo.reload({
                        where: {
                            athleteName: $("#selectTitle").val(),
                            startTime:$("#startTimes").val(),
                            endTime:$("#endTimes").val(),
                        },
                        page: {curr: 1}
                    });
                    rederTime();

                })
                //rederTime();
            });
            table.on('tool(test)', function (obj) {
                var data = obj.data;//行数据
                //console.log(obj)
                if (obj.event === 'del') {
                    layer.confirm('您真的要删除吗?', function (index) {
                        obj.del();
                        layer.close(index);
                        //使用ajax进入后台删除数据库中的数据
                        var url = "../../UserseControllerAthlete/delete";
                        var data$ = {athleteId: data.athleteId};
                        //alert(data.expertId);
                        $.post(url, data$, function (obj) {
                            if (obj.num == 1) {
                                layer.msg(obj.msg, {
                                    icon: 6,
                                    time: 500
                                }, function () {
                                    //window.location.reload();
                                    parent.layui.table.reload("demo");
                                });
                            } else {
                                layer.msg(obj.msg, {
                                    icon: 2,
                                    time: 500
                                }, function () {
                                    return;
                                });
                            }
                        }, "json");

                    });

                } else if (obj.event === 'edit') {
                    //alert(leaderId);
                    var data = obj.data;//行数据

                    //iframe层
                    layer.open({
                        type: 2,
                        title: '数据修改页面',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['95%', '85%'],
                        content: '../../pages/AtsEmpAthlete/OperAtsEmpAthlete.html?id=' + data.athleteId, //iframe的url
                        end: function () {
                            //tableTwo.reload();
                            //parent.layui.table.reload("demo");
                        }
                    });
                } else if (obj.event === 'more') {
                    var data = obj.data;//行数据
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '更多信息',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['95%', '85%'],
                        content: '../../pages/AtsEmpAthlete/MoreAtsEmpAthlete.html?id=' + data.athleteId, //iframe的url
                        /*end : function() {
                        tableTwo.reload();
                    }*/
                    });
                } else if (obj.event === 'export') {
                    var url = "../../UserseControllerExpert/exportWord?type=1&id=" + data.athleteId;
                    location.href = url;
                }
            });
            //头工具栏事件
            table.on('toolbar(test)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {

                    case 'addBtn':
                        //iframe层
                        layer.open({
                            type: 2,
                            title: '数据新增页面',
                            shadeClose: true,
                            shade: 0.8,
                            area: ['95%', '85%'],
                            content: '../../pages/AtsEmpAthlete/OperAtsEmpAthlete.html', //iframe的url
                            end: function () {
                                //tableTwo.reload();
                                //parent.layui.table.reload("demo");
                            }
                        });
                        break;
                    case 'export':
                        var data = checkStatus.data;
                        var ids = "";

                        $.each(data, function (index, item) {
                            ids += item.athleteId + ",";
                        });

                        if (ids.length == 0) {
                            layer.msg("请选择需要操作的行");
                            return;
                        }
                        $.each(data, function (index, item) {
                            setTimeout(function () {
                                var url = "../../UserseControllerExpert/exportWord?type=1&id=" + item.athleteId;
                                window.open(url);
                            }, 1000)
                        });
                        break;
                    case 'delMany':
                        var data = checkStatus.data;
                        var ids = "";
                        for (var i = 0; i < data.length; i++) {
                            ids += data[i].athleteId + ",";
                        }
                        ids = ids.slice(0, -1);
                        console.info(ids);
                        if (ids == null || ids == "") {
                            layer.msg("请至少选择一行！");
                            return;
                        } else {
                            layer.confirm('您真的要删除吗?', function (index) {
                                var url = "../../UserseControllerAthlete/deleteMany";
                                var datas = {athletes: ids};
                                $.post(url, datas, function (objs) {
                                    if (objs.num == 1) {
                                        layer.msg(objs.msg, {
                                            icon: 6,
                                            time: 500
                                        }, function () {
                                            window.location.reload();
                                            //window.location.reload();
                                            //parent.layui.table.reload("demo");
                                        });
                                    } else {
                                        layer.msg(objs.msg, {
                                            icon: 2,
                                            time: 500
                                        }, function () {
                                            return;
                                        });
                                    }
                                }, "json");
                            });
                        }
                }
                ;
            });
        //刷新时间
        layui.use('laydate', function () {
            laydate = layui.laydate;
            //开始时间、结束时间
            laydate.render({
                elem: '#startTimes',
                trigger: 'click'
            });

            laydate.render({
                elem: '#endTimes',
                trigger: 'click'
            });
        });

        /**
         * 刷新时间控件
         */
        function rederTime() {
            laydate.render({
                elem: '#startTimes',
                trigger: 'click'
            });

            laydate.render({
                elem: '#endTimes',
                trigger: 'click'
            });
        }
    });
</script>
<script>

</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container" id="insertTable">
        <a class="layui-btn layui-btn-sm" lay-event="addBtn">新增</a>
        <a class="layui-btn layui-btn-sm" id="delMany" lay-event="delMany"  data-type="reload">批量删除</a>
        <a class="layui-btn layui-btn-sm" lay-event="export">批量导出</a>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="more">查看</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="export">导出</a>
</script>
</body>
</html></title>
</head>
<body>

</body>
</html>